package org.xxforest.game.notsing.screen.rpg.layers;

import org.xxforest.game.core.scenes.scene2d.XXLayer;
import org.xxforest.game.core.scenes.scene2d.XXPointerTouch;
import org.xxforest.game.core.scenes.scene2d.events.XXKeyCode;
import org.xxforest.game.core.scenes.scene2d.events.listeners.XXKeyPressListener;
import org.xxforest.game.core.scenes.scene2d.events.listeners.XXTouchDragListener;
import org.xxforest.game.core.scenes.scene2d.events.listeners.XXTouchListener;
import org.xxforest.game.core.scenes.scene2d.events.type.XXKeyPressEvent;
import org.xxforest.game.core.scenes.scene2d.events.type.XXTouchDragEvent;
import org.xxforest.game.core.scenes.scene2d.events.type.XXTouchEvent;
import org.xxforest.game.core.scenes.scene2d.ui.XXImage;
import org.xxforest.game.core.utils.XXPoint;
import org.xxforest.game.notsing.common.SpiritManager;

public class BackgroundLayer extends XXLayer{
	
	private XXImage image ;

	public BackgroundLayer() {
		super(0,0);
	}
	
	public static BackgroundLayer create(){
		return new BackgroundLayer();
	}

	@Override
	public void onCreate() {
		image = XXImage.create("background.jpg");
		this.setWidth(image.getWidth());
		this.setHeight(image.getHeight());
		this.add(image);
		this.setAnchorPoint(image.getAnchorPoint());
		this.touchAble() ;
		
		this.setTouchDraggedEvent(new XXTouchDragListener() {

			@Override
			public boolean handle(XXTouchDragEvent event) {
				XXPointerTouch pointerTouch = event.getPointerTouch();
				XXPoint toPoint = XXPoint.create(pointerTouch.getToX(), pointerTouch.getToY());
				SpiritManager.getInstance().getMainRole().gotoPoint(toPoint);
				return true;
			}
			
		});
		
		this.setClickDownEvent(new XXTouchListener() {
			@Override
			public boolean handle(XXTouchEvent event) {
				XXPoint touchPoint = event.getPoint();
				SpiritManager.getInstance().getMainRole().gotoPoint(touchPoint);
				return true;
			}
		});
		
		this.setClickUpEvent(new XXTouchListener() {
			
			@Override
			public boolean handle(XXTouchEvent event) {
				SpiritManager.getInstance().getMainRole().stopMove() ;
				return true;
			}
		});
		
	}

	@Override
	public void dispose() {
		super.dispose();
		image.dispose() ;
	}

}
